﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lichtspiel.Display;
using Lichtspiel.Math;

namespace Lichtspiel.ECSystem
{
    public class SpriteSheet : List<Frame>
    {
        /// <summary>
        /// Generates a Spritesheet from a Gridlayouted Image.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="frameWidth"></param>
        /// <param name="frameHeight"></param>
        public SpriteSheet(Image image, int frameWidth, int frameHeight)
            : base((image.Width / frameWidth) * (image.Height / frameHeight)) {
            int columns = image.Width / frameWidth;
            int rows = image.Height / frameHeight;

            for (int y = 0; y < rows; y++) {
                for (int x = 0; x < columns; x++) {
                    this.Add(new Frame(image, new Rectangle(x * frameWidth, y * frameHeight, frameWidth, frameHeight)));
                }
            }
        }

        /// <summary>
        /// Generates a Spritesheet from a Image with defined Rectangles.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="frames"></param>
        public SpriteSheet(Image image, List<Rectangle> frames)
            : base(frames.Count) {
            foreach (Rectangle rect in frames) {
                this.Add(new Frame(image, rect));
            }
        }

        /// <summary>
        /// Generates a Spritesheet with 1 Frame.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="frame"></param>
        public SpriteSheet(Image image, Rectangle frame)
            : base(1) {
            this.Add(new Frame(image, frame));
        }

        /// <summary>
        /// Generates a Spritesheet.
        /// </summary>
        public SpriteSheet()
            : base() {
            
        }
    }
}
